#ifndef FILEMANAGER_H
#define FILEMANAGER_H

#include <QObject>
#include <QList>
#include <QMap>
#include <QJsonObject>
#include "FileInfo.h"
#include "FaceRecognition.h"

class FileManager : public QObject {
    Q_OBJECT

public:
    static FileManager& getInstance();

    void scanDirectory(const QString &path);
    QList<FileInfo> getSortedBySize() const;
    QList<FileInfo> filterByContentType(const QString &type) const;
    QList<FileInfo> filterByPerson(const QString &personNames) const;
    QList<FileInfo> filterByFileName(const QString &fileName) const;
    QList<FileInfo> filterByFileType(FileType type) const;
    QList<FileInfo> getNewFiles(const QList<FileInfo> &oldFiles) const;
    QList<FileInfo> getMissingFiles(const QList<FileInfo> &oldFiles) const;

    void saveToJson(const QString &filePath) const;
    void loadFromJson(const QString &filePath);
    void updatePeopleNamesFromFaceRecognition(const QString &faceRecognitionFilePath);

    QList<FileInfo>& getFiles();

    void updateFileInfo(const QString &filePath, const QString &contentType, const QString &contentDescription, const QVector<float> &contentEmbedding);

    QStringList getPeopleNamesFromFaceRecognition(const QString &jsonFilePath, const QString &imagePath);

private:
    FileManager(QObject *parent = nullptr);
    FileManager(const FileManager&) = delete;
    FileManager& operator=(const FileManager&) = delete;

    QList<FileInfo> m_files;

    void scanDirectoryRecursively(const QString &path);
    FileInfo getFileInfo(const QString &filePath);
    QJsonObject fileInfoToJson(const FileInfo &info) const;
    FileInfo jsonToFileInfo(const QJsonObject &json) const;
};

#endif // FILEMANAGER_H
